#include <bits/stdc++.h>

using namespace std;

const int maxn=300005;
struct Request{
    int x,id;
    const bool operator < (const Request &r) const { return x>r.x;}
};
struct Edge{
    int u,v,w;
    const bool operator < (const Edge &e) const { return w>e.w;}
};
Request r[maxn];
Edge e[maxn];
int deg[maxn],fa[maxn],cnt[maxn],siz[maxn];
struct Ans{
    int p,e;
}ans[maxn];
bool mark[maxn];
int fi(const int &x){
    if(fa[x]==x) return x;
    else return fa[x]=fi(fa[x]);
}

int main(){
    int n,m,q,x,y;
    Request *req,*red;
    int deg0,deg2,cycles;
    //freopen("ee.in","r",stdin);

    scanf("%d%d",&n,&m);
    for(int i=0;i<m;i++)
        scanf("%d%d%d",&e[i].u,&e[i].v,&e[i].w);
    scanf("%d",&q);
    for(int i=0;i<q;i++) scanf("%d",&r[i].x),r[i].id=i;
    sort(r,r+q);
    sort(e,e+m);
    req=r;
    red=r+q;
    deg0=n;
    deg2=0;
    cycles=0;
    for(int i=1;i<=n;i++) fa[i]=i,siz[i]=1;
    for(Edge *cur=e,*ed=e+m;cur<ed;cur++){
        for(;req->x>cur->w&&req<red;req++) ans[req->id]=(Ans){n-deg0-deg2+cycles,cur-e-deg2+cycles};
        x=fi(cur->u);y=fi(cur->v);
        if(deg[cur->u]==0) deg0--;
        else if(deg[cur->u]==2) deg2--,cnt[x]--;
        if(deg[cur->v]==0) deg0--;
        else if(deg[cur->v]==2) deg2--,cnt[y]--;
        deg[cur->u]++;deg[cur->v]++;
        if(deg[cur->u]==2) deg2++,cnt[x]++;
        if(deg[cur->v]==2) deg2++,cnt[y]++;
        if(mark[x]) cycles--,mark[x]=0;
        if(mark[y]) cycles--,mark[y]=0;
        if(x!=y){
            fa[x]=y;
            siz[y]+=siz[x];
            cnt[y]+=cnt[x];
            siz[x]=cnt[x]=0;
        }
        if(siz[y]==cnt[y]) mark[y]=1,cycles++;
    }
    //printf("deg: ");for(int i=1;i<=n;i++) printf("%d ",deg[i]);putchar('\n');
    //for(int i=1;i<=n;i++) printf("fa[%d]=%d,cnt[%d]=%d,siz[%d]=%d\n",i,fa[i],i,cnt[i],i,siz[i]);
    for(;req<red;req++) ans[req->id]=(Ans){n-deg0-deg2+cycles,m-deg2+cycles};

    for(int i=0;i<q;i++) printf("%d %d\n",ans[i].p,ans[i].e);
}
